#include <set>
#include <string>
using namespace std;

class Solution {
  public:
    int longestPalindrome(string s) {
        std::set<char> char_set;
        int result = 0;
        for (auto c : s) {
            if (char_set.count(c)) {
                char_set.erase(c);
                result += 2;
            } else {
                char_set.insert(c);
            }
        }
        if (char_set.empty()) return result;
        return result + 1;
    }
};
